package cn.bgs.service.impl;

import cn.bgs.common.R;
import cn.bgs.mapper.PortalMapper;
import cn.bgs.pojo.CellIntermediate;
import cn.bgs.pojo.Floor;
import cn.bgs.pojo.Portal;
import cn.bgs.service.IPortalService;
import cn.bgs.vo.PortalVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.bgs.vo.CommunityVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

import java.util.List;

/**
 * <p>
 * 房屋表 服务实现类
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@Service
public class PortalServiceImpl extends ServiceImpl<PortalMapper, Portal> implements IPortalService {

    @Autowired
    private PortalMapper portalMapper;

    @Override
    public List<Portal> appFindPortal(Integer floorId) {
        QueryWrapper<Portal> wrapper = new QueryWrapper<>();

        wrapper.eq("floor_id",floorId);
        return list(wrapper);
    }

    @Override
    public void updateHouse(PortalVo portalVo) {
        portalMapper.updateHouse(portalVo);
    }

    @Override
    public void addHouseId(PortalVo portalVo) {
        LocalDateTime localDateTime = LocalDateTime.now();
        CellIntermediate cellIntermediate = new CellIntermediate();
        BeanUtils.copyProperties(portalVo,cellIntermediate);
        cellIntermediate.setMiddleId(2);
        cellIntermediate.setCreateTime(localDateTime);
        cellIntermediate.setUpdateTime(localDateTime);
        cellIntermediate.setDeleteFlag("n");
        portalMapper.addHouseId(cellIntermediate);
    }

    @Override
    public List<PortalVo> appFindMyhouse(Integer userId) {
        return portalMapper.appFindMyhouse(userId);
    }

    @Override
    public void deleteMyhouse(Integer userId) {

        portalMapper.deleteFile(userId);
        portalMapper.deleteMiddle(userId);
        portalMapper.deleteMyhouse(userId);
    }


    @Override
    public List<CommunityVo> findplot() {
        List<CommunityVo> communityVo = this.portalMapper.findplot();
        return communityVo;
    }

    @Override
    public void delplot(Integer id) {
        this.portalMapper.delplot(id);
    }

    @Override
    public void addcommunity(CommunityVo forms) {
        this.portalMapper.addcommunity(forms);
    }

    @Override
    public void updatecommunity(CommunityVo forms) {
        this.portalMapper.updatecommunity(forms);

    }
}
